import React from 'react';
import { connect } from 'react-redux';


const mapDispatchToProps = (dispatch) => ({
    putData (keywords) {
        dispatch({
            type: 'PUT_DATA',
            task: keywords
        });
    }
});

@connect(null, mapDispatchToProps)
class Form extends React.Component {
    state = {
        task: ''
    }

    handleChange = (e) => {
        this.setState({
            task: e.target.value
        });
    }

    handleKeyUp = (e) => {
        if (e.keyCode === 13) {
            this.props.putData(this.state.task);
        }
    }

    render () {
        return (
            <div>
                <input type="text" value={this.state.task} onKeyUp={this.handleKeyUp} onChange={this.handleChange} />
            </div>
        );
    }
}
export default Form;
